<?php

namespace App\Model\Home;

use Illuminate\Database\Eloquent\Model;
use Gregwar\Captcha\CaptchaBuilder;
use Session;
use Auth;


class Login extends Model
{
    protected $table = "user";
    public $timestamps = false;
    /**
    *$tmp 为随意数 更换验证码
    *return codeimg 
    *
    */
    public static function getCode($id)
    {
    	//生成验证码图片的Builder对象，配置相应属性
        $builder = new CaptchaBuilder;
        //可以设置图片宽高及字体
        $builder->build($width = 200, $height = 42, $font = null);
        //获取验证码的内容
        $phrase = $builder->getPhrase();

        //把内容存入session
        Session::flash('code', $phrase);
        //生成图片
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-Type: image/jpeg');
        $builder->output();
       
        
    }

     /**
    *
    *
    *
    */
     public static function getLogin($arr)
     {
   
        //判断用户名 
        $count = Login::where('username',$arr->name)->where('status',0)->count();
        //dd($count);
        if($count == 0){
        return redirect('home/login')->with('u', '用户名不存在');

       }
        //判断密码
        $pwd = md5($arr->password);
        $count1 = Login::where('username',$arr->name)->where('password',$pwd)->count();
        if(!$count1){
           return redirect('home/login')->with('pwd1', '密码不正确');
        }
        //判断验证码
     /*  $code = Session::get('code');
            if($arr->input("code")!=$code){
              
              return redirect('admin/login')->with('code1', '验证码错误');
            }*/
        //验证成功 
        $user = Login::where('username',$arr->name)->first()->original;
        Session::push('user',$user);
       
       /* $data = Session::get('user');
        dd($data);*/
         return redirect('home/index');
    }


}
